package com.ss.android.b;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Base64;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.c.SharedPreferenceCompat;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.collection.WeakHandler.Callback;
import com.bytedance.common.utility.collection.WeakList;
import com.bytedance.common.utility.io.NetHackDbg;
import com.bytedance.common.utility.io.NetHackDbg.ImageType;
import com.ss.android.article.browser.R;
import com.ss.android.b.a.BaseAdsData;
import com.ss.android.b.a.m;
import com.ss.android.b.b.BaseVideoManager;
import com.ss.android.common.util.IdCache;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.image.BaseImageManager;
import com.ss.android.image.model.ImageInfo;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import pl.droidsonroids.gif.GifDrawable;

public final class AdManager implements Callback {
    public static final class c$a {
        public String a;
        public String b;

        public c$a() {

        }
    }

    public static final class b extends BaseAdsData {
        private long L;
        private long M;
        public ImageInfo a;
        long b;
        long c;
        long d;
        long e;
        long f;
        public int g;
        public long h;
        public int i;
        public int j;
        public int k;
        public int l;
        public int m;
        public int n;
        public final List o;
        public boolean p;
        public int q;
        public m r;
        public String s;

        public b() {

            this.g = 0;
            this.i = -1;
            this.j = -1;
            this.k = 0;
            this.l = 0;
            this.m = 0;
            this.n = 1;
            this.o = new ArrayList();
            this.p = false;
            this.q = 0;
        }

        public final boolean isValid() {
            boolean v0 = false;
            if ((super.isValid()) && this.a != null && this.i > 0 && this.j > 0) {
                v0 = true;
            }

            return v0;
        }

        public final void a(JSONObject arg11, long arg12) {
            JSONArray v1_2;
            int v1_1;
            JSONArray v4_2;
            JSONObject v3_1;
            m v2_2;
            long v4 = 60;
            long v0 = 30;
            int v7 = 0;
            super.initWithJO(arg11);
            this.b = arg12;
            this.a = ImageInfo.fromJson(arg11.optJSONObject("image_info"), false);
            this.L = arg11.optLong("display_time");
            this.M = arg11.optLong("display_time_ms");
            this.h = arg11.optLong("max_display_time_ms");
            this.k = arg11.optInt("predownload", 1);
            this.l = arg11.optInt("repeat");
            this.g = arg11.optInt("banner_mode");
            if (android.support.design.a.isTextEmpty(this.webUrl)) {
                this.webUrl = arg11.optString("action");
            }

            if (android.support.design.a.isTextEmpty(this.webTitle)) {
                this.webTitle = arg11.optString("title");
            }

            long v2 = arg11.optLong("leave_interval", 600);
            if (v2 >= v0) {
                v0 = v2;
            }

            this.e = v0;
            v0 = arg11.optLong("splash_interval", 14400);
            if (v0 < v4) {
                v0 = v4;
            }

            this.f = v0;
            this.d = arg11.optLong("display_after", 0);
            this.c = arg11.optLong("expire_seconds");
            String v1 = arg11.optString("display_density");
            this.m = arg11.optInt("click_btn", 0);
            this.n = arg11.optInt("skip_btn", 1);
            arg11.optInt("splash_id");
            boolean v0_1 = arg11.optInt("forbid_jump") == 1 ? true : false;
            this.p = v0_1;
            JSONArray v2_1 = arg11.optJSONArray("interval_creative");
            if (v2_1 != null && v2_1.length() > 0) {
                int v3 = v2_1.length();
                int v0_2;
                for (v0_2 = 0; v0_2 < v3; ++v0_2) {
                    JSONObject v4_1 = v2_1.optJSONObject(v0_2);
                    if (v4_1 != null) {
                        b v5 = new b();
                        v5.a(v4_1, arg12);
                        if (v5.isValid()) {
                            this.o.add(v5);
                        }
                    }
                }
            }

            int v0_2 = v1.indexOf("x");
            if (v0_2 < 0) {
                return;
            }

            if (v0_2 + 1 >= v1.length()) {
                return;
            }

            this.i = Integer.parseInt(v1.substring(0, v0_2));
            this.j = Integer.parseInt(v1.substring(v0_2 + 1));
            this.s = arg11.optString("url");
            this.q = arg11.optInt("splash_type");
            if (this.q == 0) {
                return;
            }

            this.r = new m();
            try {
                v2_2 = this.r;
                v3_1 = arg11.getJSONObject("video_info");
                v4_2 = v3_1.optJSONArray("play_track_url_list");
                if (v4_2 == null) {
                } else if (v4_2.length() == 0) {
                } else {
                    v2_2.a = new ArrayList();
                    v1_1 = 0;
                    while (v1_1 < v4_2.length()) {
                        v2_2.a.add(v4_2.getString(v1_1));
                        ++v1_1;
                    }
                }
                v4_2 = v3_1.optJSONArray("video_url_list");
                if (v4_2 == null) {

                } else if (v4_2.length() == 0) {

                } else {
                    v2_2.b = new ArrayList();
                    v1_1 = 0;
                    while (v1_1 < v4_2.length()) {
                        v2_2.b.add(v4_2.getString(v1_1));
                        ++v1_1;
                    }
                }
                v2_2.e = v3_1.optString("video_id");
                v4_2 = v3_1.optJSONArray("playover_track_url_list");
                if (v4_2 == null) {
                } else if (v4_2.length() == 0) {
                } else {
                    v2_2.c = new ArrayList();
                    v1_1 = 0;
                    while (v1_1 < v4_2.length()) {
                        v2_2.c.add(v4_2.getString(v1_1));
                        ++v1_1;
                    }
                }

                v3_1.optLong("video_group_id");
                v1_2 = v3_1.optJSONArray("action_track_url_list");
                if (v1_2 == null) {
                } else if (v1_2.length() == 0) {
                } else {
                    v2_2.d = new ArrayList();
                    while (v7 < v1_2.length()) {
                        v2_2.d.add(v1_2.getString(v7));
                        ++v7;
                    }
                }
                v3_1.optBoolean("voice_switch");
                String v0_4 = v3_1.optString("video_density");
                v1_1 = v0_4.indexOf("x");
                if (v1_1 < 0) {
                    return;
                }

                if (v1_1 + 1 >= v0_4.length()) {
                    return;
                }
                Integer.parseInt(v0_4.substring(0, v1_1));
                v2_2.videoHeight = Integer.parseInt(v0_4.substring(v1_1 + 1));
            } catch (JSONException v0_3) {
                v0_3.printStackTrace();
            }
        }

        public final long b() {
            long v2 = 40000;
            long v0 = 1000;
            long v4 = this.M;
            if (v4 <= 0) {
                v4 = this.L * v0;
            }

            if (v4 >= v0) {
                v0 = v4 > v2 ? v2 : v4;
            }

            return v0;
        }

        public final long c() {
            long v0 = this.h;
            if (v0 <= 0) {
                v0 = this.L * 1000;
            }

            return v0;
        }
    }

    public static final class c$c {
        public final List a;
        public final List b;
        public final d c;

        c$c(byte arg1) {
            this();
        }

        private c$c() {
            this.a = new ArrayList();
            this.b = new ArrayList();
            this.c = new d();
        }

        public final void a(JSONArray arg5, long arg6) {
            int v0_1;
            if (arg5 != null) {
                try {
                    int v1 = arg5.length();
                    v0_1 = 0;
                    while (true) {
                        if (v0_1 >= v1) {
                            return;
                        }
                        JSONObject v2 = arg5.optJSONObject(v0_1);
                        if (v2 != null) {
                            b v3 = new b();
                            v3.a(v2, arg6);
                            if (v3.isValid()) {
                                this.a.add(v3);
                            }
                        }
                        ++v0_1;
                        continue;
                    }
                } catch (Exception v0) {
                    return;
                }


            }
        }

        public final void a(JSONArray arg5) {
            int v0_1;
            if (arg5 != null) {
                try {
                    int v1 = arg5.length();
                    v0_1 = 0;
                    while (true) {
                        label_4:
                        if (v0_1 >= v1) {
                            return;
                        }

                        JSONObject v2 = arg5.optJSONObject(v0_1);
                        if (v2 != null) {
                            c$a v2_1 = AdManager.a(v2);
                            if (v2_1 != null) {
                                this.b.add(v2_1);
                            }
                        }
                        ++v0_1;
                        continue;
                    }
                } catch (Exception v0) {
                    return;
                }


            }
        }

        public final void a(JSONObject arg7) {
            int v0_1;
            long unitMS = 1000;
            if (arg7 == null) {
                return;
            }

            try {
                this.c.interval = (((long) arg7.optInt("interval"))) * unitMS;
                this.c.splashInterval = (((long) arg7.optInt("splash_interval"))) * unitMS;
                this.c.leaveInterval = (((long) arg7.optInt("leave_interval"))) * unitMS;
                this.c.showMode = arg7.optInt("show_mode");
                JSONArray v1 = arg7.optJSONArray("app_list");
                if (v1 == null) {
                    return;
                }

                if (v1.length() <= 0) {
                    return;
                }

                v0_1 = 0;
                while (true) {
                    label_31:
                    if (v0_1 >= v1.length()) {
                        return;
                    }

                    JSONObject v2 = v1.optJSONObject(v0_1);
                    String name = v2.optString("name");
                    String pkg = v2.optString("package");
                    String downloadUrl = v2.optString("download_url");
                    if (!android.support.design.a.isTextEmpty(name)
                            && !android.support.design.a.isTextEmpty(pkg)
                            && !android.support.design.a.isTextEmpty(downloadUrl)) {
                        e v3_1 = new e();
                        v3_1.pkg = pkg;
                        v3_1.ruleId = v2.optInt("rule_id");
                        v3_1.url = v2.optString("url");
                        v2.optInt("width");
                        v2.optInt("height");
                        v2.optInt("button_top");
                        v2.optString("button_text");
                        v2.optString("hint_text");
                        this.c.e.add(v3_1);
                    }

                    ++v0_1;
                    continue;
                }
            } catch (Exception v0) {
                v0.printStackTrace();
            }
        }
    }

    public static final class d {
        public long interval;
        public long splashInterval;
        public long leaveInterval;
        public int showMode;
        public ArrayList e;

        public d() {

            this.showMode = 0;
            this.e = new ArrayList();
        }
    }

    public static final class e {
        public String url;
        public String pkg;
        public int ruleId;

        public e() {

        }
    }

    final class f {
        final HashMap a;

        f(byte arg1) {
            this();
        }

        private f() {

            this.a = new HashMap();
        }

        public final void a(JSONArray arg5) {
            if (arg5 != null) {
                int v0;
                for (v0 = 0; v0 < arg5.length(); ++v0) {
                    JSONObject v1 = arg5.optJSONObject(v0);
                    int v2 = v1.optInt("status", -1);
                    if (v2 >= 0) {
                        this.a.put(Integer.valueOf(v2), Integer.valueOf(v1.optInt("count")));
                    }
                }
            }
        }

        public final JSONArray a() {
            JSONArray v1 = new JSONArray();
            Iterator<Integer> v2 = this.a.keySet().iterator();
            try {
                while (v2.hasNext()) {
                    JSONObject jsonObject = new JSONObject();
                    int v0_1 = v2.next().intValue();
                    jsonObject.put("status", v0_1);
                    jsonObject.put("count", this.a.get(Integer.valueOf(v0_1)));
                    v1.put(jsonObject);
                }
            } catch (Exception v0) {
            }

            return v1;
        }
    }

    static class g extends Thread {
        private g() {

        }

        g(byte arg1) {
            this();
        }

        public void a() {
        }

        public final void run() {
            try {
                this.a();
            } catch (Throwable v0) {
            }
        }
    }

    static final Object a = new Object();
    final WeakHandler b;
    public long c;
    public long d;
    public boolean e;
    public Context mContext;
    public c$c g;
    HashMap h;
    Set i;
    private static AdManager sInstance = null;
    private final WeakList k;
    private final Point l;
    private boolean m;

    private AdManager(Context context) {
        this.b = new WeakHandler(Looper.getMainLooper(), ((Callback) this));
        this.k = new WeakList();
        this.l = new Point();
        this.c = 0;
        this.d = 0;
        this.e = false;
        this.m = false;
        this.g = new c$c((byte) 0);
        new IdCache(50);
        new HashMap();
        this.mContext = context.getApplicationContext();
    }

    public final void a() {
        long v8;
        String v6;
        String v5;
        String v4;
        int v0 = 0;
        if (!this.m) {
            this.m = true;
            Object v2 = a;
            synchronized (v2) {
                SharedPreferences sharedPreferences = this.mContext.getSharedPreferences("ss_splash_ad", 0);
                v4 = sharedPreferences.getString("splash_str", "");
                v5 = sharedPreferences.getString("ad_area_str", "");
                v6 = sharedPreferences.getString("bind_app_str", "");
                v8 = sharedPreferences.getLong("fetch_time", 0);
                sharedPreferences.getLong("adsage_close_protect", 0);
                this.i = new HashSet();
                this.h = new HashMap();
                try {
                    String v1 = sharedPreferences.getString("last_logs", "");
                    if (!android.support.design.a.isTextEmpty(v1)) {
                        JSONArray v7 = new JSONArray(v1);
                        int v1_1;
                        for (v1_1 = 0; v1_1 < v7.length(); ++v1_1) {
                            JSONObject v10 = v7.optJSONObject(v1_1);
                            if (v10 != null && (v10.has("id")) && (v10.has("history"))) {
                                long v12 = v10.optLong("id");
                                JSONArray v10_1 = v10.optJSONArray("history");
                                f v11 = new f((byte) 0);
                                v11.a(v10_1);
                                this.h.put(Long.valueOf(v12), v11);
                            }
                        }
                    }

                    v1 = sharedPreferences.getString("preload_ids", "");
                    if (android.support.design.a.isTextEmpty(v1)) {
                    } else {
                        JSONArray v3_1 = new JSONArray(v1);
                        while (v0 < v3_1.length()) {
                            this.i.add(Long.valueOf(v3_1.optLong(v0)));
                            ++v0;
                        }
                    }
                    c$c v0_3 = AdManager.a(v4, v5, v6, v8);
                    this.g = v0_3;
                    this.a(v0_3);
                } catch (Exception v0_2) {
                }
            }
        }
    }

    public static AdManager getInstance(Context context) {
        synchronized (AdManager.class) {
            if (sInstance == null) {
                sInstance = new AdManager(context);
            }
        }
        return sInstance;
    }

    public final b a(boolean arg17, long arg18) {
        Object v3_1;
        Object v11;
        b v3;
        Object v12 = null;
        long v4 = System.currentTimeMillis();
        long v6 = com.ss.android.b.bb.a().b();
        c$c v2 = this.g;
        if (v2 == null) {
            v3 = null;
            return v3;
        }

        try {
            Iterator v13 = v2.a.iterator();
            do {
                if (!v13.hasNext()) {
                    v11 = v12;
                    break;
                }

                v11 = v13.next();
                if (!((b) v11).o.isEmpty()) {
                    Iterator v14 = ((b) v11).o.iterator();
                    do {
                        if (v14.hasNext()) {
                            v3_1 = v14.next();
                            if (v3_1 == null) {
                                continue;
                            }

                            if (!((b) v3_1).isValid()) {
                                continue;
                            }

                            if (!this.a(((b) v3_1), v4, v6, arg17, arg18)) {
                                continue;
                            }
                            this.b();
                            return (AdManager.b) v3_1;
                        }
                        break;
                    } while (true);
                }
                AdManager v2_2 = this;
                v3_1 = v11;
                boolean v8 = arg17;
                long v9 = arg18;
                if (!v2_2.a(((b) v3_1), v4, v6, v8, v9)) {
                    continue;
                } else {
                    break;
                }
            }
            while (true);
        } catch (Exception v2_1) {
            v11 = null;
        }
        this.b();
        v3 = (AdManager.b) v11;
        return v3;
    }

    public final boolean a(ImageInfo arg2) {
        boolean v0 = arg2 == null || (android.support.design.a.isTextEmpty(arg2.mKey)) ? false : this.a(arg2.mKey);
        return v0;
    }

    public final boolean a(m arg3) {
        boolean v0 = arg3 == null || (android.support.design.a.isTextEmpty(arg3.e)) ? false : new BaseVideoManager(this.mContext).a(arg3.e);
        return v0;
    }

    @SuppressLint(value = {"UseSparseArrays"})
    public final boolean tryShowImageSplash(Context arg9, b arg10, ImageView arg11, ImageView arg12, pl.droidsonroids.gif.h arg13, Boolean[] arg14) {
        Bitmap v1_3;
        String v2;
        String v0_5;
        BaseImageManager v6;
        boolean v0_4;
        String v3;
        int v4;
        int v0_2;
        boolean v1;
        if (arg9 != null && arg10 != null && arg12 != null) {
            boolean v5;
            try {
                Resources v0_1 = arg9.getResources();
                v5 = v0_1.getBoolean(R.bool.u);
                v1 = v0_1.getBoolean(R.bool.v);
                if (arg11 != null) {
                    v0_2 = arg10.g == 1 ? 1 : 0;
                    if (v0_2 == 0) {
                        v4 = 0;
                    } else {
                        v4 = 1;
                    }
                } else {
                    v4 = 0;
                }

                if (v4 != 0 && (v5)) {
                    ViewGroup.LayoutParams v0_3 = arg11.getLayoutParams();
                    v0_3.height = this.a(v1);
                    arg11.setScaleType(ImageView.ScaleType.FIT_XY);
                    arg11.setLayoutParams(v0_3);
                }

                v3 = arg10.a != null ? arg10.a.mKey : null;
                if (android.support.design.a.isTextEmpty(v3)) {
                    v0_4 = false;
                    return v0_4;
                }

                v6 = new BaseImageManager(arg9);
                if (!BaseImageManager.a()) {
                    return false;
                }

                v0_5 = v6.getExternalCacheFile(v3);
                if (!new File(v0_5).isFile()) {
                    v2 = v6.getInternalCacheFile(v3);
                } else {
                    v2 = v0_5;
                }

                if (NetHackDbg.b(v2) == ImageType.GIF) {
                    v1 = true;
                } else {
                    v1 = false;
                }
                if (arg14 != null) {
                    arg14[0] = Boolean.valueOf(v1);
                }
            } catch (Exception v0) {
                Logger.w("AdManager", "tryShowImageSplash exception: " + v0);
                return false;
            }

            v0_2 = 0;
            if (!v1) {
            } else {
                try {
                    GifDrawable v1_2 = new GifDrawable(v2);
                    v1_2.d = arg13;
                    arg12.setImageDrawable(((Drawable) v1_2));
                    if (arg10.l == 0) {
                        v1_2.a = 0;
                    }
                    v0_2 = 1;
                } catch (Exception v0) {
                }
            }
            try {
                if (v0_2 != 0) {

                } else {
                    v0_2 = 640;
                    int v2_1 = 960;
                    v1_3 = v6.a(v3, v0_2, v2_1);
                    if (v1_3 != null) {
                    } else {
                        Logger.d("SplashActivity", "splash ad not ready");
                    }
                    if (v1_3 == null) {
                        return false;
                    }
                    arg12.setImageBitmap(v1_3);
                }
                try {
                    com.ss.android.b.bb.a().a(System.currentTimeMillis());
                    if (arg10.q == 0) {
                        BaseAdsData.trackAdShow(arg9, "splash_ad", ((BaseAdsData) arg10), 3);
                    }

                    if (arg11 != null) {
                        v0_2 = 8;
                        if (v4 != 0) {
                            if (v5) {
                                v0_2 = 4;
                            } else {
                                v0_2 = 0;
                            }
                        }
                        arg11.setVisibility(v0_2);
                    }
                    arg12.setVisibility(View.VISIBLE);
                    return true;
                } catch (Exception v0) {
                    label_107:
                    Logger.w("AdManager", "tryShowImageSplash exception: " + v0);
                    return false;
                }
            } catch (Exception v0) {
            } catch (Throwable v0_6) {
                Logger.d("SplashActivity", "load splash bitmap exception: " + v0_6);
            }
        }

        return false;
    }

    public final c$a a(String arg6, String arg7) {
        c$a v0_2;
        c$a v2 = null;
        c$c v3 = this.g;
        if (v3 != null && !android.support.design.a.isTextEmpty(arg6)) {
            int v1 = !android.support.design.a.isTextEmpty(arg7) ? 1 : 0;
            try {
                Iterator v3_1 = v3.b.iterator();
                do {
                    if (!v3_1.hasNext()) {
                        return v2;
                    }

                    Object v0_1 = v3_1.next();
                    if (!arg6.equals(((c$a) v0_1).a)) {
                        continue;
                    }

                    if (v1 == 0) {
                        return (c$a) v0_1;
                    }

                    if (!arg7.equals(((c$a) v0_1).b)) {
                        continue;
                    }

                    return (c$a) v0_1;
                }
                while (true);
            } catch (Exception v0) {
                return v2;
            }
        } else {
            v0_2 = v2;
        }

        return v0_2;
    }

    private int a(boolean arg7) {
        int v0_1;
        com.bytedance.common.b.b.a(this.mContext, this.l);
        float v0 = this.mContext.getResources().getDisplayMetrics().density;
        if ((((double) v0)) <= 1.1) {
            v0_1 = 100;
        } else if ((((double) v0)) <= 1.6) {
            v0_1 = 960;
        } else {
            v0_1 = 1260;
        }

        int v1 = this.l.y;
        if (!arg7) {
            v1 -= UIUtils.getStatusBarHeight(this.mContext);
        }

        return v1 * 200 / v0_1;
    }

    static c$a a(JSONObject arg3) {
        c$a v1_1;
        c$a v0 = null;
        try {
            v1_1 = new c$a();
            v1_1.a = arg3.optString("area");
            v1_1.b = arg3.optString("type");
            arg3.optLong("interval");
            arg3.optString("title");
            arg3.optString("wap_app_url");
            if (TextUtils.isEmpty(v1_1.a)) {
                return v0;
            }

            if (TextUtils.isEmpty(v1_1.b)) {
                return v0;
            }
        } catch (Exception v1) {
            return v0;
        }

        return v1_1;
    }

    private static c$c a(String arg3, String arg4, String arg5, long arg6) {
        c$c v1 = new c$c((byte) 0);
        if (!android.support.design.a.isTextEmpty(arg3)) {
            try {
                v1.a(new JSONArray(arg3), arg6);
            } catch (Exception v0) {
            }
        }

        if (!android.support.design.a.isTextEmpty(arg4)) {
            try {
                v1.a(new JSONArray(arg4));
            } catch (Exception v0) {
            }
        }

        if (!android.support.design.a.isTextEmpty(arg5)) {
            try {
                v1.a(new JSONObject(arg5));
            } catch (Exception v0) {
                v0.printStackTrace();
            }
        }

        return v1;
    }

    static void a(int arg1, m arg2, BaseVideoManager arg3) {
        if (arg2 != null && arg3 != null && (arg1 == 2 || arg1 == 3) && (arg3.a(arg2.e))) {
            arg2.f = arg3.d(arg2.e);
        }
    }

    private void a(c$c arg7) {
        if (arg7 != null && (NetworkUtils.isNetworkAvailable(this.mContext))) {
            try {
                BaseImageManager v4 = new BaseImageManager(this.mContext);
                BaseVideoManager v3 = new BaseVideoManager(this.mContext);
                if (!BaseImageManager.isExternalStorageMounted()) {
                    return;
                }

                new com.ss.android.b.e(this, arg7.a, v3, v4, arg7.c.e).start();
            } catch (Throwable v0) {
            }
        }
    }

    private boolean a(b arg9, long arg10, long arg12, boolean arg14, long arg15) {
        int v3;
        boolean v2;
        if (arg9.b + arg9.d * 1000 > arg10) {
            v2 = false;
            v3 = 1;
        } else if (arg9.b + arg9.d * 1000 + arg9.c * 1000 < arg10) {
            v2 = false;
            v3 = 2;
        } else {
            if (!arg14 && arg10 - arg15 < arg9.e * 1000) {
                v2 = false;
                v3 = 3;
            } else if (arg10 - arg12 < arg9.f * 1000) {
                v2 = false;
                v3 = 4;
            } else if (arg9.a(this.mContext)) {
                v2 = false;
                v3 = 5;
            } else if (arg9.q == 0 && !this.a(arg9.a)) {
                v2 = false;
                v3 = 6;
            } else if (arg9.j <= arg9.i) {
                v2 = false;
                v3 = 7;
            } else if (arg9.q == 2 && !this.a(arg9.r)) {
                v2 = false;
                v3 = 8;
            } else if (arg9.q == 3 && (this.a(arg9.r)) && !this.a(arg9.a)) {
                v2 = false;
                v3 = 9;
            } else if (arg9.q == 3 && !this.a(arg9.r) && (this.a(arg9.a))) {
                v2 = false;
                v3 = 10;
            } else if (arg9.q == 3 && !this.a(arg9.r) && !this.a(arg9.a)) {
                v2 = false;
                v3 = 11;
            } else {
                v2 = true;
                v3 = 0;
            }
        }
        if (this.h != null) {
            if (!this.h.containsKey(Long.valueOf(arg9.id))) {
                this.h.put(Long.valueOf(arg9.id), new f((byte) 0));
            }

            Object v0 = this.h.get(Long.valueOf(arg9.id));
            if (v0 == null) {
                return v2;
            }

            if (v3 < 0) {
                return v2;
            }

            int v1 = 0;
            if (((f) v0).a.containsKey(Integer.valueOf(v3))) {
                v1 = ((Integer) ((f) v0).a.get(Integer.valueOf(v3))).intValue();
            }

            ((f) v0).a.put(Integer.valueOf(v3), Integer.valueOf(v1 + 1));
        }

        return v2;
    }

    private boolean a(String arg3) {
        boolean v0 = android.support.design.a.isTextEmpty(arg3) ? false : new BaseImageManager(this.mContext).existsInExternalCache(arg3);
        return v0;
    }

    final boolean a(BaseVideoManager arg16, BaseImageManager arg17, b arg18) {
        int v1_2;
        boolean v1_1;
        int v12;
        String v8;
        String v7;
        String v6;
        String v14;
        String v4;
        m v13;
        boolean v11 = false;
        if (arg18 != null && arg16 != null) {
            try {
                v13 = arg18.r;
                if (v13 != null && v13.b != null && v13.b.size() > 0) {
                    v4 = b(arg18.s);
                    v14 = v13.e;
                    v6 = arg16.a + BaseVideoManager.b(v14);
                    if (!android.support.design.a.isTextEmpty(arg16.b)) {
                        v7 = arg16.b + BaseVideoManager.b(v14);
                    } else {
                        v7 = null;
                    }
                } else {
                    return false;
                }
                v8 = BaseVideoManager.c(v14);
                v12 = 1;
                if (arg18.q != 2) {

                } else if (!arg16.a(v14)) {
                    try {
                        v11 = com.ss.android.b.bb.a().a(null, -1, v4, v13.b, v6, v7, v8, null, null);
                    } catch (Throwable v1) {
                        if (com.ss.android.b.bb.a().a(com.ss.android.b.bb.a().a(this.mContext, v1))) {

                        } else {
                            v12 = 0;
                        }
                    }
                    if ((v11) || v12 == 0) {
                        v1_1 = v11;
                    } else {
                        try {
                            v11 = com.ss.android.b.bb.a().a(null, -1, v4, v13.b, v6, v7, v8, null, null);
                            v1_1 = v11;
                        } catch (Throwable v1) {
                            v1_1 = v11;
                            v1.printStackTrace();
                            return v1_1;
                        }
                    }

                    if (!v1_1) {
                        return v1_1;
                    }

                    try {
                        v13.f = arg16.d(v14);
                        return v1_1;
                    } catch (Throwable v2) {
                        v2.printStackTrace();
                        return v1_1;
                    }
                } else {
                    v13.f = arg16.d(v14);
                    v1_1 = true;
                    return v1_1;
                }
            } catch (Throwable v1) {
                v1_1 = v11;
                v1.printStackTrace();
                return v1_1;
            }


            try {
                label_89:
                if (arg18.q != 3) {
                    return false;
                }

                if (arg17 == null) {
                    return false;
                }

                if (!arg16.a(v14)) {

                } else {
                    v13.f = arg16.d(v14);
                    return this.a(arg17, arg18.a);
                }
            } catch (Throwable v1) {
                v1_1 = v11;
                v1.printStackTrace();
                return v1_1;
            }

            try {
                v11 = com.ss.android.b.bb.a().a(null, -1, v4, v13.b, v6, v7, v8, null, null);
                v1_2 = 1;
            } catch (Throwable v1) {
                if (com.ss.android.b.bb.a().a(com.ss.android.b.bb.a().a(this.mContext, v1))) {
                    v1_2 = 1;
                } else {
                    v1_2 = 0;
                }
            }
            if (!v11 && v1_2 != 0) {
                try {
                    v11 = com.ss.android.b.bb.a().a(null, -1, v4, v13.b, v6, v7, v8, null, null);
                } catch (Throwable throwable) {

                }
            }
            if (v11) {
                v13.f = arg16.d(v14);
            }
            if ((this.a(arg17, arg18.a)) && (v11)) {
                return true;
            } else {
                return false;
            }

        } else {
            v1_1 = false;
        }

        return v1_1;
    }

    final boolean a(BaseImageManager arg13, ImageInfo arg14) {
        String v7;
        String v6;
        String v5;
        boolean v11 = true;
        boolean v10 = false;
        if (arg14 == null) {
            return v10;
        }

        try {
            String v0_1 = arg14.mKey;
            v5 = arg13.getExternalImageSaveDir(v0_1);
            v6 = arg13.getInternalImageSaveDir(v0_1);
            v7 = BaseImageManager.getCacheFileName(v0_1);
            if (!arg13.existsInExternalCache(v0_1)) {
                try {
                    v10 = com.ss.android.b.bb.a().a(null, -1, arg14.mUri, arg14.mUrlList, v5, v6, v7, null, null);
                } catch (Throwable v0) {
                    if (com.ss.android.b.bb.a().a(com.ss.android.b.bb.a().a(this.mContext, v0))) {
                    } else {
                        v11 = v10;
                    }
                }
                boolean v0_2;
                if (!v10) {
                    if (!v11) {
                        return v10;
                    }

                    try {
                        v0_2 = com.ss.android.b.bb.a().a(null, -1, arg14.mUri, arg14.mUrlList, v5, v6, v7, null, null);
                    } catch (Throwable v0) {
                        label_40:
                        v0_2 = v10;
                    }
                } else {
                    v0_2 = v10;
                }

                return v0_2;
            }
        } catch (Throwable v0) {
        }
        boolean v0_2 = true;
        return v0_2;

    }

    private static String b(String arg4) {
        String v1 = "";
        if (!android.support.design.a.isTextEmpty(arg4)) {
            try {
                String v0_1 = new String(Base64.decode(arg4, 0), "utf-8");
                return v0_1;
            } catch (Throwable v0) {
            }
        }

        return v1;
    }

    final void b() {
        Iterator v3;
        JSONArray v2;
        SharedPreferences.Editor v1 = this.mContext.getSharedPreferences("ss_splash_ad", 0).edit();
        try {
            if (this.h != null) {
                v2 = new JSONArray();
                v3 = this.h.keySet().iterator();
                while (v3.hasNext()) {
                    long v4 = ((Long) v3.next()).longValue();
                    Object v0_1 = this.h.get(Long.valueOf(v4));
                    if (v0_1 == null) {
                        continue;
                    }

                    JSONObject v6 = new JSONObject();
                    v6.put("id", v4);
                    v6.put("history", ((f) v0_1).a());
                    v2.put(v6);
                }

                v1.putString("last_logs", v2.toString());
            }

            if (this.i != null) {
                v2 = new JSONArray();
                v3 = this.i.iterator();
                while (v3.hasNext()) {
                    v2.put(v3.next());
                }

                v1.putString("preload_ids", v2.toString());
            }

            SharedPreferenceCompat.commit(v1);
            return;
        } catch (Exception v0) {
            return;
        }
    }

    public final b c() {
        return this.a(true, com.ss.android.b.bb.a().c());
    }

    public final boolean d() {
        Object v0_1;
        boolean v2 = false;
        String v4 = com.ss.android.b.bb.a().d();
        ArrayList v0 = this.g.c.e;
        ArrayList v5 = new ArrayList();
        Iterator v1 = v0.iterator();
        while (v1.hasNext()) {
            v0_1 = v1.next();
            if (ToolUtils.isAppInstalled(this.mContext, ((e) v0_1).pkg)) {
                continue;
            }

            v5.add(v0_1);
        }

        if (v5.size() <= 0) {
            v0_1 = null;
        } else {
            int v3 = -1;
            int v1_1;
            boolean bingo = false;
            for (v1_1 = 0; v1_1 < v5.size(); ++v1_1) {
                v0_1 = v5.get(v1_1);
                if (!android.support.design.a.isTextEmpty(v4) && !android.support.design.a.isTextEmpty(((e) v0_1).pkg) && (v4.equals(((e) v0_1).pkg))) {
                    bingo = true;
                    break;
                }
            }

            if (!bingo) {
                v1_1 = v3;
            }
            int v0_2 = v1_1 + 1;
            if (v0_2 < 0 || v0_2 >= v5.size()) {
                v0_2 = 0;
            }

            v0_1 = v5.get(v0_2);
        }

        if (v0_1 != null && (this.a(com.bytedance.common.utility.aa.md5(((e) v0_1).url)))) {
            v2 = true;
        }

        return v2;
    }

    public final int e() {
        int v0_1;
        Resources v0 = this.mContext.getResources();
        boolean v1 = v0.getBoolean(R.bool.u);
        boolean v2 = v0.getBoolean(R.bool.v);
        if (v1) {
            v0_1 = this.a(v2);
        } else {
            Drawable v0_2 = v0.getDrawable(com.ss.android.article.browser.R.drawable.splash_banner);
            v0_1 = v0_2 != null ? v0_2.getIntrinsicHeight() : -1;
            if (v0_1 > 0) {
                return v0_1;
            }

            float v0_3 = this.mContext.getResources().getDisplayMetrics().density;
            if ((((double) v0_3)) <= 1.1) {
                return 100;
            }

            if ((((double) v0_3)) <= 1.6) {
                return 160;
            }

            if ((((double) v0_3)) > 2.1 && v0_3 < 5f) {
                return ((int) (v0_3 * 100f));
            }

            v0_1 = 200;
        }

        return v0_1;
    }

    public final void handleMsg(Message message) {
        switch (message.what) {
            case 10: {
                this.e = false;
                if (!(message.obj instanceof c$c)) {
                    return;
                }

                Object v0 = message.obj;
                this.c = System.currentTimeMillis();
                this.a(((c$c) v0));
                if (v0 != null) {
                    this.g = ((c$c) v0);
                }

                Iterator v0_1 = this.k.iterator();
                while (v0_1.hasNext()) {
                    v0_1.next();
                }
            }
            case 11: {
                this.e = false;
                break;
            }
        }
    }
}

